$(function () {
	if (url('type')) {
		vm.q.type = url('type');
	} 
	
    $("#jqGrid").jqGrid({
        url: baseURL + 'bdbusiness/aahotinfomation/list',
        datatype: "json",
        postData: vm.q,
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true ,hidden: true},
			{ label: '标题', name: 'title', index: 'title', width: 180 }, 			
			{ label: '来源', name: 'source', index: 'source', width: 80 }, 			
			{ label: '发布时间', name: 'pubdate', index: 'pubdate', width: 80 }, 			
			{ label: '详情', name: 'url', index: 'url', width: 80, 
		          formatter: function (value, options, row) {
		        	  return '<input type="button" class="btn" style="padding: 1px 10px;" onClick="window.open($(this).parent().text().trim())" value="详情"/>'
		        	  		+'<p style="display:none;">'+row.url+'</p>';
		          }
				}, 			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		q:{
			type: '',
			title: '',
		},
		showList: true,
		title: null,
        showGraph:{
        	data: [{
                    name: '热点资讯库',
                    x: 120,
                    y: 50
                }, {
                    name: '结果数据',
                    x: 300,
                    y: 50
                }, {
                    name: '需求信息',
                    x: 50,
                    y: 100
                }, {
                    name: '行业动态',
                    x: 80,
                    y: 100
                }, {
                    name: '行业信息',
                    x: 110,
                    y: 100
                }, {
                    name: '企业信息',
                    x: 140,
                    y: 100
                }
            ],
            links: [{
                source: 0,
                target: 1
            },{
                source: 2,
                target: 0
            },{
                source: 3,
                target: 0
            },{
                source: 4,
                target: 0
            },{
                source: 5,
                target: 0
            }],
		},
		aaHotinfomation: {}
	},
	methods: {
		query: function () {
            $("#jqGrid").setGridParam({'page': 1});
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.aaHotinfomation = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.aaHotinfomation.id == null ? "bdbusiness/aahotinfomation/save" : "bdbusiness/aahotinfomation/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.aaHotinfomation),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "bdbusiness/aahotinfomation/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "bdbusiness/aahotinfomation/info/"+id, function(r){
                vm.aaHotinfomation = r.aaHotinfomation;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                postData: vm.q,
                page:page
            }).trigger("reloadGrid");
		}
	}
});